package com.cysyz.mylib.commonservice.area.impl;

import java.util.ArrayList;
import java.util.List;

import com.cysyz.mylib.commonservice.area.AreaService;
import com.cysyz.mylib.commonservice.area.domain.Province;
import com.cysyz.mylib.commonservice.area.vo.AreaVo;
import com.cysyz.mylib.commonservice.servicesupport.CommonServiceSupport;
import com.cysyz.mylib.dao.Conds;
public class AreaServiceImpl extends CommonServiceSupport implements AreaService {
	
	@Override
	public List<AreaVo> findAllPrivice()
	{
		String queryPrefix = " select new com.cernet.emall.vo.AreaVo(pk,name) from Province ";
		Conds conds = new Conds();
		conds.addFilter("province", "pk", ">", "0");
		return this.list(AreaVo.class, conds, queryPrefix, null);
	}
	
	@Override
	public List<AreaVo> findCityByProvince(int provinceid)
	{
		String queryPrefix = " select new com.cernet.emall.vo.AreaVo(pk,name) from City ";
		Conds conds = new Conds();
		conds.addFilter("city", "province.pk", ">", provinceid);
		conds.addFilter("city", "pk", ">", "0");
		return this.list(AreaVo.class, conds, queryPrefix, null);
	}
	
	@Override
	public List<AreaVo> findTownByCity(int cityid)
	{
		String queryPrefix = " select new com.cernet.emall.vo.AreaVo(pk,name) from Town where city.pk=? and pk>0 ";
		Conds conds = new Conds();
		conds.addFilter("town", "city.pk", ">", cityid);
		conds.addFilter("town", "pk", ">", "0");
		return this.list(AreaVo.class, conds, queryPrefix, null);
	}
	
	@Override
	public List<AreaVo> findStreetByTown(int townid)
	{
		String queryPrefix = " select new com.cernet.emall.vo.AreaVo(pk,name) from Street where town.pk=? and pk>0 ";
		Conds conds = new Conds();
		conds.addFilter("street", "town.pk", ">", townid);
		conds.addFilter("street", "pk", ">", "0");
		return this.list(AreaVo.class, conds, queryPrefix, null);
	}
	
	@Override
	public List<AreaVo> findAllCity()
	{
		String queryPrefix = " select new com.cernet.emall.vo.AreaVo(pk,name) from City ";
		return this.list(AreaVo.class, queryPrefix, null);
	}
	
	@Override
	public Province findByProvincepk(Integer provincepk)
	{
		return this.get(Province.class, provincepk);
	}
	
	@Override
	public List<Province> findGPSProvince()
	{
		Conds conds = new Conds();
		List<String> names = new ArrayList<String>();
		names.add("北京");
		names.add("河北");
		names.add("河南");
		names.add("吉林");
		names.add("山东");
		names.add("山西");
		names.add("天津");
		conds.addFilter("province", "name", "in", names );
		return this.list(Province.class, conds);
				
	}
}
